/******************************************/
/************* GPStrac Header *************/
/******************************************/
/*
* FILE: gpsTrac.h
* AUTHOR: Ram Subramanian and Nicolas Papin
* PROJECT: CS 3251 Project 2 - Professor Traynor
* DESCRIPTION: Shared application header.
* PURPOSE: Defines some shared structure and data types that will be used in both GPStrac client and server.
*/

#ifndef _GPSTRAC_H
#define _GPSTRAC_H

#include <stdio.h>          /* for printf() and fprintf() */
#include <sys/socket.h>		/* for socket(), connect(), send(), and recv() */
#include <arpa/inet.h>		/* for sockaddr_in and inet_addr() */
#include <stdlib.h>         /* supports all sorts of functionality */
#include <unistd.h>         /* for close() */
#include <pthread.h>		/* for Pthreads */

//
// Definitions
//
/*
* Server ip address and port.
*/
#define SERV_PORT 25352

/*
* Number of characters in a user id.
*/
#define USER_ID_LEN 20


//
// ENUMS
//
/*
* Used to indicate the type of request being made by the client to the server.
* Defined as follows:
* UPDATE_LOC - Update the sending client's gps location.  The following message will contain relevant data.
* VIEW_LOC - Retrieve the current location of a list of clients.  The following message will contain this list.
* LOC_HIST - Retrieve the history of a specified user.  The following message will denote the user.
* LEAVE - Disconnect from the server.  There will not a following message.
*/
typedef enum
{
    LOG_IN,
    UPDATE_LOC,
    VIEW_LOC,
    LOC_HIST,
    LEAVE
} req_t;

/*
* Used to indicate the type of response from the server.
* Defined as follows:
* REQ_OK - Used to indicate a successfully completed request.  An expected return will follow.
* REQ_INVALID - Used to indicate that the client's previous request was invalid.
* USER_INVALID - Used to indicate that the server does not recognize and refuses to serve the user.
* SERV_ERR - Used to indicate that the server experienced an error while handling the request.
*/
typedef enum
{
    REQ_OK,
    REQ_INVALID,
    USER_INVALID,
    SERV_ERR
} resp_t;


//
// Shared Structures
//
/*
* Represents a GPS coordinate.
* inval - flag used to represent "location" for a logoff event.
* lat - the latitude of the coordinate.  + for North, - for South.
* lon - the longitude of the coordinate. + for East, - for West.
*/
typedef struct gpsCoord
{
    int inval;
    int lon;
    int lat;
} gpsCoord_t;

/*
* Used as a preface to client->server communications.
* Contains information used by the server to help interpret an upcomming communication.
* cmd - used to indicate to the server the current command.
* client - used for server side identification of the client.
* msgLen - indicates the length of the follow up message for this message.  These follow up messages are generally used for arguments to the given command.
*/
typedef struct clntReq
{
    req_t cmd;
    uint32_t msgLen;
} clntReq_t;

/*
* Used as a preface for server->client responses.
* Contains information to help the client understand the status of his requests.
* resp - used to indicate the server's response to the previous request.
* client - used for server side identification of the client.
* retLen - indicates the length of any data that is being returned as a result of the request.
*/
typedef struct servResp
{
    resp_t resp;
    uint32_t retLen;
} servResp_t;

#endif
